using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.obj
{
[System.Serializable]
public  class Model : Singleton
 {

    public string name  = "";
     public bool isShowName ;
     public string icon  = "";
     public string model  = "";
     


    public const int TYPE_ID = 1657632328;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(6);
        os.WriteSize(Tag.BOOL | (1 << Tag.TAG_SHIFT));  os.WriteBool(enable);  
         os.WriteSize(Tag.INT | (2 << Tag.TAG_SHIFT));  os.WriteInt(cfgId);  
         os.WriteSize(Tag.STRING | (101 << Tag.TAG_SHIFT));  os.WriteString(name);  
         os.WriteSize(Tag.BOOL | (102 << Tag.TAG_SHIFT));  os.WriteBool(isShowName);  
         os.WriteSize(Tag.STRING | (103 << Tag.TAG_SHIFT));  os.WriteString(icon);  
         os.WriteSize(Tag.STRING | (104 << Tag.TAG_SHIFT));  os.WriteString(model);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.BOOL | (1 << Tag.TAG_SHIFT)):   enable = os.ReadBool(); break;  
             case (Tag.INT | (2 << Tag.TAG_SHIFT)):   cfgId = os.ReadInt(); break;  
             case (Tag.STRING | (101 << Tag.TAG_SHIFT)):   name = os.ReadString(); break;  
             case (Tag.BOOL | (102 << Tag.TAG_SHIFT)):   isShowName = os.ReadBool(); break;  
             case (Tag.STRING | (103 << Tag.TAG_SHIFT)):   icon = os.ReadString(); break;  
             case (Tag.STRING | (104 << Tag.TAG_SHIFT)):   model = os.ReadString(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Model");
        ele.WriteStartElement("enable"); ele.WriteAttributeString("id", "1"); ele.WriteBool(enable); ele.WriteEndElement();
         ele.WriteStartElement("cfgId"); ele.WriteAttributeString("id", "2"); ele.WriteInt(cfgId); ele.WriteEndElement();
         ele.WriteStartElement("name"); ele.WriteAttributeString("id", "101"); ele.WriteString2(name); ele.WriteEndElement();
         ele.WriteStartElement("isShowName"); ele.WriteAttributeString("id", "102"); ele.WriteBool(isShowName); ele.WriteEndElement();
         ele.WriteStartElement("icon"); ele.WriteAttributeString("id", "103"); ele.WriteString2(icon); ele.WriteEndElement();
         ele.WriteStartElement("model"); ele.WriteAttributeString("id", "104"); ele.WriteString2(model); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  enable = ele.ReadBool(); break; 
                 case 2:  cfgId = ele.ReadInt(); break; 
                 case 101:  name = ele.ReadString2(); break; 
                 case 102:  isShowName = ele.ReadBool(); break; 
                 case 103:  icon = ele.ReadString2(); break; 
                 case 104:  model = ele.ReadString2(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "enable":  enable = ele.ReadBool(); break; 
                 case "cfg_id":  cfgId = ele.ReadInt(); break; 
                 case "name":  name = ele.ReadString2(); break; 
                 case "is_show_name":  isShowName = ele.ReadBool(); break; 
                 case "icon":  icon = ele.ReadString2(); break; 
                 case "model":  model = ele.ReadString2(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
